const synth = window.speechSynthesis;
const msg = new SpeechSynthesisUtterance();

export interface VoiceConfig {
    text: string
    lang?: string
    volume?: number
    rate?: number
    pitch?: number
}


export function speak(config: VoiceConfig) {
    msg.text = config.text;
    msg.lang = config.lang || 'zh-CN';
    msg.volume = config.volume || 1;

    msg.rate = config.rate || 1;//语速
    msg.pitch = config.pitch || 1;//音高
}

export function speakChinese(text: string) {
    msg.text = text;
    msg.lang = "zh-CN";
    msg.volume = 1;

    msg.rate = 1;//语速
    msg.pitch = 1;//音高

    synth.speak(msg);
}

export function speakEnglish(text: string) {
    msg.text = text;
    msg.volume = 1;
    msg.rate = 1;//语速
    msg.pitch = 1;//音高

    synth.speak(msg);
}

export function stopSpeak() {
    synth.cancel();
}

